package com.qiankan.qmsj.net;

import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Administrator on 2017/8/17.
 */

public class APIHub {
    //    private final OkHttpClient mHttpClient;
    private static APIHub sInstance;
    private BaseServer mBaseService;

    private APIHub() {
        /*mHttpClient = new OkHttpClient.Builder()
                .connectTimeout(10, TimeUnit.SECONDS)
                .readTimeout(20, TimeUnit.SECONDS)
                .followRedirects(true)
                .retryOnConnectionFailure(true)
                .build();*/
        buildRetrofitService();
    }

    public static APIHub getsInstance() {
        if (sInstance == null) {
            synchronized (APIHub.class) {
                if (sInstance == null)
                    sInstance = new APIHub();
            }
        }
        return sInstance;
    }

    private void buildRetrofitService() {
        /**
         * 这里的baseUrl就是网络请求URL相对固定的地址，一般包括请求协议（如Http）、域名或IP地址、端口号等，
         * 当然还会有很多其他的配置，下文会详细介绍。还有addConverterFactory方法表示需要用什么转换器来解析返回值，
         * GsonConverterFactory.create()表示调用Gson库来解析json返回值.
         */
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://116.62.228.94:8080/majia/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        mBaseService = retrofit.create(BaseServer.class);
    }

    public BaseServer getBaseService() {
        return mBaseService;
    }
}
